package com.lcj;

import com.geccocrawler.gecco.GeccoEngine;
import com.geccocrawler.gecco.request.HttpPostRequest;
import com.geccocrawler.gecco.spring.SpringGeccoEngine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@Configuration
public class DxrcLoginApplication {

    /*以下是模拟登陆程序*/
    /*输入你的用户名及密码 ，这里输入*/
    private static String userName = "15874991816";
    private static String password = "cx821202";
    private static String dxrcLoginURL = "http://zp.hnzpsc.com/index.php?m=Home&c=Members&a=login";

    @Bean
    public SpringGeccoEngine initGecco() {
        return new SpringGeccoEngine() {
            @Override
            public void init() {
                HttpPostRequest httppost = new HttpPostRequest(dxrcLoginURL);

                httppost.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36");
                httppost.addHeader("Accept","application/json, text/javascript, */*; q=0.01");
                httppost.addHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
                httppost.addHeader("X-Requested-With","XMLHttpRequest");
                httppost.addField("username",userName);
                httppost.addField("password",password);
                httppost.addField("expire","1");
                httppost.addField("geetest_challenge","");
                httppost.addField("geetest_validate","");
                httppost.addField("geetest_seccode","");
                GeccoEngine.create()
                        .pipelineFactory(springPipelineFactory)
                        .classpath("com.lcj")
                        .start(httppost)
                        .interval(1000)
                        .debug(false)
                        .start();
            }
        };
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(DxrcLoginApplication.class, args);
    }
}
